#include "stdafx.h"
//-------------------------------------------------------------------------------------------------
//ImageProps.cpp  - Encapsulates the Behaviour and Properties of an Image        
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2011 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk Feb 2011
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
#include <string>

#include "ImageProps.h"
#include "ImageObjectTypeTool.h"
#include "SelectType.h"
#include "ImageDataset.h"

const char * const ImageProps::xmlImageObjectSection = "ImageObject";
const char * const ImageProps::xmlImageObjectType = "Type";
const char * const ImageProps::xmlImage = "Image";
const char * const ImageProps::xmlBrightness = "Brightness";
const char * const ImageProps::xmlContrast = "Contrast";
const char * const ImageProps::xmlNotes = "Notes";
const char * const ImageProps::BrightnessMid = "0";
const char * const ImageProps::ContrastMid = "0";

ImageProps::ImageProps()	: 
	_pSelImageType('\0'),
	_pSelImageObject('\0'),
	_DicomRef(""),
	_Brightness(ImageProps::BrightnessMid),
	_Contrast(ImageProps::ContrastMid),
	_Notes("")
{
	_DicomRef = "";
}

ImageProps::ImageProps(ImageType *pImageType)	:  
	_pSelImageObject('\0'),
	_DicomRef(""), 
	_Brightness(ImageProps::BrightnessMid),
	_Contrast(ImageProps::ContrastMid),
	_Notes("")
{
	_pSelImageType = pImageType;
	_DicomRef = "";
}

ImageProps::~ImageProps()
{
	ClearAllImageProperties();
	ClearAllImageObjects();
	ClearAllImageObjectsTypeInfo();
}

void ImageProps::ResetToDefaults()
{
	_pSelImageObject = '\0';
	_pSelImageType = '\0';
	_DicomRef = "";
	_Brightness = ImageProps::BrightnessMid;
	_Contrast = ImageProps::ContrastMid;
	_Notes = "";


	ClearAllImageProperties();
	ClearAllImageObjects();	

	size_t cnt = _imageObjectsTypeInfo.size();
	if (cnt > 0 )
	{
		for (size_t x = 0; x < cnt; x++)
			_imageObjectsTypeInfo[x]->_ImageObjectsCreated = 0;
	}
}


bool  ImageProps::SetDicomRef(const char *pDicomRef)
{  
	bool rc = false;

	if (IsValidDicomRef(pDicomRef))
	{
		_DicomRef = pDicomRef;
		rc = true;
	}

	return rc; 
}

bool	ImageProps::SetNotes(const char *notes) 
{ 
	bool rc = false;

	if (std::strlen(notes) <= ImageProps::NotesLengthMax ) 
	{
		_Notes = notes;
		rc = true;
	}
	return rc;
}

bool	ImageProps::SetContrast(int val)
{
	bool rc = false;
	if ((val >= ImageProps::ContrastMin) && (val <= ImageProps::ContrastMax)) 
	{
		char buffer[5+1];
		if ( _itoa_s( val, &buffer[0], 5, 10 ) == 0 )
		{
			_Contrast = buffer;
			rc = true;
		}
	}
 	return rc;
}

bool	ImageProps::SetBrightness(int val)
{
	bool rc = false;
	if ((val >= ImageProps::BrightnessMin) && (val <= ImageProps::BrightnessMax)) 
	{
		char buffer[5+1];
		if ( _itoa_s( val, &buffer[0], 5, 10 ) == 0 )
		{
			_Brightness = buffer;
			rc = true;
		}
	}
 	return rc;
}

bool  ImageProps::AddImageObjectTypeInfo(const char * ImageObjectTypeName)
{
	bool rc = false;

	ImageObjectTypeInfo *pImageObjectTypeInfo = new ImageObjectTypeInfo();
	pImageObjectTypeInfo->_ImageObjectTypeName = ImageObjectTypeName;
	pImageObjectTypeInfo->_ImageObjectsCreated = 0;

	_imageObjectsTypeInfo.push_back(pImageObjectTypeInfo);
	rc = true;

	return rc;
}

int	ImageProps::IncExpertObjsCreated(const char * ImageObjectTypeName) //called only by ImageObject::Create()
{
	int rc = -1;

	int index = GetIndexForInfoAboutImageObjectsCreatedOfType(ImageObjectTypeName);
	if ( index > -1 )
	{
		_imageObjectsTypeInfo[index]->_ImageObjectsCreated++;
		rc = _imageObjectsTypeInfo[index]->_ImageObjectsCreated;
	}
	return rc;
}

int	ImageProps::DecExpertObjsCreated(const char * ImageObjectTypeName) //called only by ImageProps::DeleteImageObject()
{
	int rc = -1;

	int index = GetIndexForInfoAboutImageObjectsCreatedOfType(ImageObjectTypeName);
	if ( index > -1 )
	{
		_imageObjectsTypeInfo[index]->_ImageObjectsCreated--;
		rc = _imageObjectsTypeInfo[index]->_ImageObjectsCreated;
	}
	return rc;
}

bool ImageProps::CanCreateExpertImageObject(ImageObjectType *pImageObjectType) 
{
	bool rc = false;

	if ( pImageObjectType != '\0')
	{
		if ( pImageObjectType->GetExpertMaxObjs() == -1) 
			rc = true;
		else
		{
			int index = GetIndexForInfoAboutImageObjectsCreatedOfType(pImageObjectType->GetName());
			if ( index > -1 )
			{
				if ( _imageObjectsTypeInfo[index]->_ImageObjectsCreated < pImageObjectType->GetExpertMaxObjs() )
					rc = true;
			}
		}
	}
	return rc;
}


ImageObject *ImageProps::CreateImageObject(ImageObjectType *pImageObjType)	//called from PtShapeTool::OnLButtonDown or similar
{
	ImageObject *rc = '\0';

	if ((rc = ImageObject::Create(pImageObjType, this)) != '\0')
	{
		 _imageObjects.push_back(rc);
	}
	return rc;
}



bool ImageProps::DeleteImageObject(ImageObject *pImageObj)
{
	bool rc = false;

	if (pImageObj != '\0')
	{
		std::vector <ImageObject *>::iterator Iter;
		for ( Iter = _imageObjects.begin( ) ; Iter != _imageObjects.end( ) ; Iter++ )
		{
			if (*Iter == pImageObj)
			{
				DecExpertObjsCreated(pImageObj->GetImageObjectType()->GetName());
				delete *Iter;
				Iter = _imageObjects.erase(Iter);
				pImageObj = '\0';
				rc = true;
				break;
			}
		}
	}
	return rc;
}

bool	ImageProps::DeleteSelImageObject(ImageObjectTypeTool *pSelTool)
{
	bool rc = false;

	ImageObject *pSelImageObject = GetSelImageObject();
	if (pSelImageObject != '\0')
	{
		if ( DeleteImageObject(pSelImageObject))
		{
			pSelImageObject = '\0';
			rc = SetSelImageObject(GetFirstImageObject(pSelTool));
		}
	}
	return rc;
}

ImageProp *ImageProps::CreateImageProperty(const char *xmlPropName, const char *xmlPropValue, ImageTypeProp *pImagePropType)	//called from LoadXML
{
	ImageProp *rc = '\0';

	if ( (pImagePropType != '\0') && (xmlPropName != '\0') && (xmlPropValue != '\0') )
	{
		if ( HasProperty( xmlPropName ) == false )	//property names must be unique
		{
			if ((rc = ImageProp::CreateImageProp(xmlPropName, xmlPropValue, pImagePropType)) != '\0')
			{
				_imageProperties.push_back(rc);
			}
		}
	}
	return rc;
}

ImageProp  *ImageProps::GetImageProperty(const char *Name)
{
	ImageProp  *rc = '\0';

	if (Name != '\0')
	{
		size_t cnt = _imageProperties.size();
		if (cnt > 0 )
		{
			for (size_t x = 0; x < cnt; x++)
			{
				std::string imagePropName = Name;
				if (imagePropName == _imageProperties[x]->GetPropName())
				{
					rc = _imageProperties[x];
					break;
				}
			}
		}
	}
	return rc;
}

bool ImageProps::SetImageProperty(const char *Name, const char *Value)
{
	bool rc = false;

	if ((Name != '\0') && (Value != '\0'))
	{
		size_t cnt = _imageProperties.size();
		if (cnt > 0 )
		{
			for (size_t x = 0; x < cnt; x++)
			{
				std::string imagePropName = Name;
				if (imagePropName == _imageProperties[x]->GetPropName())
				{
					_imageProperties[x]->SetPropValue(Value);
					rc = true;
					break;
				}
			}
		}
	}

	return rc;
}

int		ImageProps::GetImageObjectCnt(const char *ImageObjectTypeName)
{
	int rc = 0;

	if (ImageObjectTypeName)
	{
		size_t cnt = _imageObjects.size();
		if (cnt > 0 )
		{
			for (size_t x = 0; x < cnt; x++)
			{
				if ( strcmp(_imageObjects[x]->GetImageObjectType()->GetName(), ImageObjectTypeName) == 0)
					rc++;
			}
		}
	}
	return rc;
}

ImageObject *ImageProps::GetImageObject(const char *ImageObjectTypeName, int index)
{
	ImageObject *rc = '\0';

	if (ImageObjectTypeName)
	{
		int found = 0;
		size_t cnt = _imageObjects.size();
		if (cnt > 0 )
		{
			for (size_t x = 0; x < cnt; x++)
			{
				if ( strcmp(_imageObjects[x]->GetImageObjectType()->GetName(), ImageObjectTypeName) == 0)
				{
					if (found == index)
					{
						rc = _imageObjects[x];
						break;
					}
					found++;
				}
			}
		}
	}
	return rc;
}

ImageObject *ImageProps::GetFirstImageObject(ImageObjectTypeTool *pSelTool)
{
	ImageObject *rc = '\0';

	if (pSelTool != '\0')
	{
		std::string toolForObjectTypeName = pSelTool->GetImageObjectType()->GetName();
		if (toolForObjectTypeName == SelectType::baseClassName )
			rc = GetImageObject(0);
		else
			rc = GetImageObject(pSelTool->GetImageObjectType()->GetName(), 0);
	}
	return rc;
}

ImageObject *ImageProps::GetImageObject(const char *Name)
{
	ImageObject *rc = '\0';

	if (Name != '\0')
	{
		size_t cnt = _imageObjects.size();
		if (cnt > 0 )
		{
			for (size_t x = 0; x < cnt; x++)
			{
				std::string imageObjectName = Name;
				if (_imageObjects[x]->GetName() == imageObjectName)
				{
					rc = _imageObjects[x];
					break;
				}
			}
		}
	}
	return rc;
}

ImageProp  *ImageProps::GetSelImageObjectProperty(const char *ImageObjectPropertyName)
{
	ImageProp  *rc = '\0';

	if ((ImageObjectPropertyName != '\0') && (_pSelImageObject != '\0'))
	{
		rc = _pSelImageObject->GetProperty(ImageObjectPropertyName);
	}

	return rc;
}


ImageObject *ImageProps::GetNextIncompatibleImageObject(int startIndex, ImageType *pImageType)
{
	ImageObject *rc = '\0';

	ImageObject *pImageObject = '\0';
	int cnt = GetImageObjectCnt();
	for (int x = 0; x < cnt; x++ )
	{
		if ((pImageObject = GetImageObject(x)) != '\0')
		{
			if (pImageType->LookupImageObjectType(pImageObject->GetName()) == '\0')
			{
				rc = pImageObject;
				break;
			}
		}
	}

	return rc;
}

bool ImageProps::SetSelImageType(ImageType *pImageType, ImageObjectTypeTool *pSelTool) 
{ 
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("ImageProps::SetSelImageType()", "ImageImageType [%s], Tool for Image Object[%s]: remove superfluous prop, create any missing props, delete any image objects not available for this type, if Notify then update UI", pImageType->GetName(), (pSelTool != '\0') ? pSelTool->GetImageObjectType()->GetName() : "pSelTool is null" );
#endif
//!!!!!!!!!!!!!!!

	if ( _pSelImageType == pImageType)
		rc = true;
	else
	{
		rc = ((_pSelImageType = pImageType) != '\0') ? true : false;

		if ( rc == true )
		{
										//remove any superfluous properties for this new image type
			ClearAllImagePropertiesNotForSelectedType();
										//create any missing properties for this new image type
			ImageTypeProp *pImageTypeProp = '\0';
			int PropCnt = _pSelImageType->GetImagePropertyCnt();
			for (int x = 0; x < PropCnt; x++ )
			{
				if ((pImageTypeProp = _pSelImageType->GetImageProperty(x)) != '\0')
				{
					if ( HasProperty (pImageTypeProp->GetName()) == false )
					{					
						if ( CreateImageProperty(pImageTypeProp->GetName(), pImageTypeProp->GetDefaultValue(), pImageTypeProp) == false)
						{
							rc = false;
							break;
						}
					}
				}
			}
										//delete any image objects not available for this type
			ImageObject *pImageObject = '\0';
			int ObjCnt = GetImageObjectCnt();
			for (int x = 0; x < ObjCnt; x++ )
			{
				if ((pImageObject = GetNextIncompatibleImageObject(x, _pSelImageType)) != '\0')
				{
					if ( pImageObject == _pSelImageObject) 
						rc = DeleteSelImageObject(pSelTool);  //calls DecExpertObjsCreated to update _imageObjectsTypeInfo
					else
						rc = DeleteImageObject(pImageObject); //calls DecExpertObjsCreated to update _imageObjectsTypeInfo
					if (rc == false )
						break;
				}
			}
		}
	}
	return rc; 
}

bool ImageProps::SetSelImageObject(ImageObject *pSelImageObject)
{ 
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("ImageProps::SetSelImageObject()", "Image Object [%s]: find image object in the collection for this image and set it as the currently selected image object", (pSelImageObject != '\0') ? pSelImageObject->GetName() : "pSelImageObject is null" );
#endif
//!!!!!!!!!!!!!!!

	_pSelImageObject = '\0';

	if ( pSelImageObject != '\0')
	{
		size_t cnt = _imageObjects.size();
		for (size_t x = 0; x < cnt; x++)
		{
			if ( _imageObjects[x] == pSelImageObject)
			{
				_pSelImageObject = pSelImageObject;
				rc = true;
				break;
			}
		}
	}
	return rc;
}

bool ImageProps::SaveImageObjects(TiXmlElement *pImageXml, ImageObjectType *pImageObjectType)
{
	bool rc = false;

	//<Image Note="good image" Quality=5 >1.2.826.999999.1.9999.1.20080115012154575.1.3.0
	//		<ImageObject Type="Ovary-ETS" Note="this is good quality image of left ovary" PtCnt="2" x1="233" y1="456" x2="123" y2="789">09877655</ImageObject>
	//</Image>

	if ((pImageXml != '\0') && (pImageObjectType != '\0'))
	{
		if ( ImageDataset::DeleteAllSubSections (pImageXml, ImageProps::xmlImageObjectSection ))
		{
			ImageObject *pImageObject = '\0';
			//iterate through list _imageObjects of the give type for this image
			rc = true;
			int cnt = GetImageObjectCnt(pImageObjectType);
			for (int x = 0; x < cnt; x++ )
			{
				if ((pImageObject = GetImageObject(pImageObjectType, x)) != '\0')
				{
					TiXmlElement *pXmlImageObject = pImageObject->GetImageObjectXml(pImageXml);	//all subsections deleted, so it must return '\0'
					if (pXmlImageObject == '\0')
					{
						if ((pXmlImageObject = TinyXmlLib::CreateSection (pImageXml, ImageProps::xmlImageObjectSection, pImageObject->GetName() )) != '\0')
							pXmlImageObject->SetAttribute(ImageProps::xmlImageObjectType, pImageObject->GetImageObjectType()->GetName());
					}
					if ( pImageObject->SaveProperties(pXmlImageObject) == false)
					{
						rc = false;
						break;
					}
				}
			}
		}
	}
	return rc;
}

bool ImageProps::SaveProperties(TiXmlElement *pImageXml)
{
	bool rc = false;

	if ( pImageXml != '\0' )
	{
		std::string xmlTypeName = pImageXml->Value();
		if ( xmlTypeName == ImageProps::xmlImage)
		{
			ImageType *pImageType = GetSelImageType();
			if (pImageType != '\0')
			{
				rc = true;				
								//ImageType
				if ( ImageDataset::SetXmlAttribute(pImageXml, ImageType::xmlImageType, pImageType->GetName()) == false)
					rc = false;
								//Brightness
				if ( ImageDataset::SetXmlAttribute(pImageXml, ImageProps::xmlBrightness, GetBrightnessStr()) == false)
					rc = false;
								//Contrast
				if ( ImageDataset::SetXmlAttribute(pImageXml, ImageProps::xmlContrast, GetContrastStr()) == false)
					rc = false;
								//Notes
				if ( ImageDataset::SetXmlAttribute(pImageXml, ImageProps::xmlNotes, GetNotes()) == false)
					rc = false;
								//XML defined properties
				ImageTypeProp *pImageTypeProp = '\0';
				int cnt = pImageType->GetImagePropertyCnt();
				for (int x = 0; x < cnt; x++ )
				{
					if ((pImageTypeProp = pImageType->GetImageProperty(x)) != '\0')
					{
						ImageProp *pProp = '\0';		
						if ( (pProp = GetImageProperty(pImageTypeProp->GetName())) == '\0')
							rc = false;
						else
						{
							if ( pProp->SaveValueTo(pImageXml) == false)
							{
								rc = false;
								break;
							}
						}
					}
				}
			}

		}
	}
	return rc;
}


bool ImageProps::LoadImageObject(TiXmlElement *pImageObjectXml, ImageObjectType *pImageObjectType)
{
	bool rc = true;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("ImageProps::LoadImageObject()", "CreateImageObject and Load its properties from xml" );
#endif
//!!!!!!!!!!!!!!!

	if ( (pImageObjectXml != '\0') && (pImageObjectType != '\0'))
	{
		ImageObject *pImageObject = CreateImageObject(pImageObjectType);
		if (pImageObject != '\0') 
			rc = pImageObject->LoadProperties(pImageObjectXml);
	}
	return rc;
}

bool ImageProps::LoadProperties(TiXmlElement *pImageXml, ImageType *pImageType, ImageObjectTypeTool *pSelTool)
{
	bool rc = true;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("ImageProps::LoadProperties()", "set selected image type and load image props from XML file; brightness, contrast, notes, other defined props for image type (creating XML elements for any that don't already exist)" );
#endif
//!!!!!!!!!!!!!!!

	if ( (pImageXml != '\0') && (pImageType != '\0'))
	{
		std::string elementType = pImageXml->Value();
		if (elementType == ImageProps::xmlImage )
		{
			if (SetSelImageType(pImageType, pSelTool) == true)
			{
				rc = true;
								//Brightness - creates attribute in XML if it doesn't exist
				if (SetBrightness(atoi(ImageDataset::GetXmlAttribute(pImageXml, ImageProps::xmlBrightness, ImageProps::BrightnessMid))) == false)
					rc = false;
								//Contrast- creates attribute in XML if it doesn't exist
				if (SetContrast(atoi(ImageDataset::GetXmlAttribute(pImageXml, ImageProps::xmlContrast, ImageProps::ContrastMid))) == false)
					rc = false;
								//Notes- creates attribute in XML if it doesn't exist
				if (SetNotes(ImageDataset::GetXmlAttribute(pImageXml, ImageProps::xmlNotes, "...")) == false)
					rc = false;
								//XML defined Properties - creates attributes in XML if they don't exist
				ImageTypeProp *pPropType = '\0';
				int cnt = pImageType->GetImagePropertyCnt();
				for (int x = 0; x < cnt; x++ )
				{
					if ((pPropType = pImageType->GetImageProperty(x)) != '\0')
					{
						const char *Name = pPropType->GetName();
						const char *Value = ImageDataset::GetXmlAttribute(pImageXml, Name, pPropType->GetDefaultValue()); 
						if ( SetImageProperty(Name, Value) == false)
						{
							rc = false;
							break;
						}
					}
				}
			}
		}
	}
	return rc;
}



bool ImageProps::DeleteNextEmptyImageObjectXml(TiXmlElement *pImageXml)
{
	bool rc = false;

	if ( pImageXml != '\0')
	{
		for( TiXmlNode *gchild = pImageXml->FirstChild(); gchild; gchild = gchild->NextSibling() )
		{
			if (gchild->Type() == TiXmlNode::TINYXML_ELEMENT)
			{
				TiXmlElement *imageObjectXml = dynamic_cast<TiXmlElement *>(gchild);
				if (imageObjectXml)
				{
					std::string imageObjectNameXml = imageObjectXml->GetText();
					if (GetImageObject(imageObjectNameXml.c_str()) == '\0')
					{
						assert(pImageXml->RemoveChild(gchild));
						rc= true;
						break;
					}
				}
			}
		}
	}
	return rc;
}

//............................................................................................
//private member functions
//............................................................................................

bool  ImageProps::HasProperty(const char *Name)
{
	bool rc = false;

	if ( Name != '\0' )
	{
		std::string propName = Name;
		size_t cnt = _imageProperties.size();
		for (size_t x = 0; x < cnt; x++)
		{
			if (propName == _imageProperties[x]->GetPropName() )
			{
				rc = true;
				break;
			}
		}
	}
	return rc;
}


int	 ImageProps::GetIndexForInfoAboutImageObjectsCreatedOfType(const char * imageObjectTypeName)
{
	int rc = -1;

	if (imageObjectTypeName != '\0')
	{
		size_t cnt = _imageObjectsTypeInfo.size();
		for (size_t x = 0; x < cnt; x++)
		{
			if ( _imageObjectsTypeInfo[x]->_ImageObjectTypeName == imageObjectTypeName) 
			{
				rc = x;
				break;
			}
		}
	}
	return rc;
}

bool ImageProps::ClearAllImageProperties()
{
	bool rc = false;

	size_t cnt = _imageProperties.size();
	if (cnt > 0 )
	{
		for (size_t x = 0; x < cnt; x++)
			delete _imageProperties[x];
		_imageProperties.clear();
		rc = true;
	}

	return rc;
}

bool ImageProps::ClearAllImagePropertiesNotForSelectedType()
{
	bool rc = true;

	ImageProp *pImageProp = '\0';
	std::vector <ImageProp *>::iterator Iter = _imageProperties.begin();
	while( Iter != _imageProperties.end() )
	{
		if ((pImageProp = *Iter) != '\0')
		{
			if (_pSelImageType->HasProperty(pImageProp) == '\0')
			{
				delete pImageProp;
				Iter = _imageProperties.erase(Iter);
			}
			else
				Iter++;
		}
		else
			Iter++;
	}
	return rc;
}

bool ImageProps::ClearAllImageObjects()
{
	bool rc = false;

	size_t cnt = _imageObjects.size();
	if (cnt > 0 )
	{
		for (size_t x = 0; x < cnt; x++)
			delete _imageObjects[x];
		_imageObjects.clear();
		rc = true;
	}

	return rc;
}

bool ImageProps::ClearAllImageObjectsTypeInfo()
{
	bool rc = false;

	size_t 	cnt = _imageObjectsTypeInfo.size();
	if (cnt > 0 )
	{
		for (size_t x = 0; x < cnt; x++)
			delete  _imageObjectsTypeInfo[x];
		_imageObjectsTypeInfo.clear();
	}
	return rc;
}


//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------

